package com.jjx.trainingapi.config;


import cn.dev33.satoken.exception.NotLoginException;
import com.jjx.trainingapi.common.ErrorCode;
import com.jjx.trainingapi.common.MyException;
import com.jjx.trainingapi.common.RT;
import com.jjx.trainingapi.enums.RHttpStatusEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author LoveHuahua
 * @date 2022年04月30日 13:10
 * @description believe in yourself
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     *
     * @param myException
     * @return
     */
    @ExceptionHandler(MyException.class)
    public RT handleCustomException(MyException myException) {
        myException.printStackTrace();
        return RT.error(myException);
    }


    @ExceptionHandler(Exception.class)
    public RT handleException(Exception exception) {
        exception.printStackTrace();
        return RT.error(RHttpStatusEnum.SERVER_ERROR);
    }



    @ExceptionHandler(NotLoginException.class)
    public RT handleNotLoginException(NotLoginException exception) {
        exception.printStackTrace();
        return RT.error(new MyException(ErrorCode.NOT_LOGIN));
    }


}
